import { Notify } from 'vant';

// 搜索页的仓库数据
import request from '@/api'

const actions = {
  async getProductList({ commit },data) {

    let { value, index } = data
    console.log(value)
    // console.log(index)
    if (!index) {
      index = 0
    }
    const result = await request.search.reqGetProductList(value)
   
    let distance = index * 20
    // console.log(distance)
    // const start = 0 + distance
    let end = 20 + distance

    if (result.code == 200) {
       
        const directlyList = result.data.directlyList.slice(0, end)
       
       
        commit('SAVE_PRODUCTLIST',{directlyList,value})
      } else {
        Notify({ type: 'warning', message: '网络不太好，请稍后重试~' });
      }
    }
  }



const mutations = {
  SAVE_PRODUCTLIST(state, data) {
    
    state.directlyList = data.directlyList
    state.value = data.value
  }
}

const state = {

  directlyList: [],  //产品列表数组
  value:'',   //搜索关键词
}


const getters = {}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced:true
}